package com.huang.loop;

/**
 学习目标：
 for循环的应用
 */
public class ForDemo2 {
    public static void main(String[] args) {
        //输出1-100之间的数
        for (int i = 1; i <= 100; i++) {
            System.out.println(i);
        }

        System.out.println("--------------------");
        //计算1到100之间的和
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum = sum + i;
        }
        System.out.println("和为：" + sum);
        System.out.println("--------------------");
        //计算1到100之间的奇数和
        int sum1 = 0;
        for (int i = 1; i < 100; i += 2) {
            sum1 = sum1 + i;
        }
        System.out.println("奇数和为：" + sum1);
        System.out.println("--------------------");
        int sum2 = 0;
        for (int i = 1; i <= 100; i++) {
            if (i % 2 == 1) {
                sum2 = sum2 + i;
            }
        }
        System.out.println("奇数和为：" + sum2);
    }
}